import { WeaTools } from 'ecCom';
import window from '../util';
export const url = '/api/formmode/page/'
export const newUrl = '/api/cube/'
export const CallAPI = (url, method, params) => {
    return new Promise((resolve, reject) => {
        WeaTools.callApi(url, method, params).then(({ noRight, ...data }) => {
            if (noRight) {
                // reject();
                // window.weaHistory.push('/main/cube/noright');
                resolve({ noRight, ...data } as any)
            } else {
                resolve(data as any)
            }
        })
    })
}

window.WeaTools = WeaTools;

const init = (params) => {
    const result = CallAPI(`${url}init`, "get", params);
    return result;
}
const update = (params) => {
    const result = CallAPI(`${url}update`, "post", params);
    return result;
}
const datas = (params) => {
    const result = CallAPI(`${url}datas`, "post", params);
    return result;
}
const dataKey = (params) => {
    const result = CallAPI(`${newUrl}search/getList`, "post", params);
    return result;
}

const getCountData = (params) => {
    const result = CallAPI(`/api/cube/search/getCountData`, "post", params);
    return result;
}

const getGroupData = (params) => {
    const result = CallAPI(`/api/cube/search/getGroupData`, "post", params);
    return result;
}

const cleanCol = (params) =>{
    const result = CallAPI(`${newUrl}search/cleanCol`, "get", params);
    return result;
}
const edit = (params) => {
    return CallAPI(`${url}edit`, "post", params);
}

const doInterface = (params) => {
    return CallAPI(`${newUrl}expand/interface`, "post", params);
}
const initSearch = (params) => {
    return CallAPI(`${newUrl}search/init`, "get", params);
}
const deleteData = (params) => {
    return CallAPI(`${newUrl}expand/deleteData`, "get", params);
}
const getConditionInfo = (params) => {
    return CallAPI(`${newUrl}search/condition`, "get", params);
}
const getAdvancedInfo = (params) => {
    return CallAPI(`${newUrl}search/advanced`, "get", params);
}
const getTitleField = (params) => {
    return CallAPI(`${newUrl}search/getTitleField`, "get", params);
}
const getBarCode = (params) => {
    return CallAPI(`${newUrl}expand/getBarCode`, "get", params);
}
const getQrCode = (params) => {
    return CallAPI(`${newUrl}expand/getQrCode`, "get", params);
}
const getConditionParams = (params) => {
    return CallAPI(`${newUrl}search/getConditionParams`, "get", params);
}
const getTemplates = (params) => {
    return CallAPI(`${newUrl}search/getTemplate`, "get", params);
}
const getTemplateInfo = (params) => {
    return CallAPI(`${newUrl}search/getTemplateInfo`, "get", params);
}
const saveTemplate = (params) => {
    return CallAPI(`${newUrl}search/saveTemplate`, "POST", params);
}
const batchShareCondition = (params) => {
    return CallAPI(`${newUrl}right/getConditions`, "get", params);
}

const saveBatchShare = (params) => {
    return CallAPI(`${newUrl}right/saveBatchShare`, "get", params);
}
const analyzePageExpandLinkUrl = (params) => {
    return CallAPI(`${newUrl}expand/analyzePageExpandLinkUrl`, "get", params);
}
const getMapTitles = (params) => {
    return CallAPI(`${newUrl}expand/getMapTitles`, "get", params);
}
const batchSave = (params) => {
    return CallAPI(`${newUrl}expand/batchSave`, "get", params);
}
const saveTabBatch = (params) => {
    return CallAPI('/api/cube/tab/saveTabBatch', "post", params);
}

const getTemplateList = (params) => {
    return CallAPI(`${newUrl}search/getTemplateList`, "get", params);
}

const saveOrUpdateTemplate = (params) => {
    return CallAPI(`${newUrl}search/saveOrUpdateTemplate`, "POST", params);
}

const deleteTemplate = (params) => {
    return CallAPI(`${newUrl}search/deleteTemplate`, "get", params);
}

const setDefault = (params) => {
    return CallAPI(`${newUrl}search/setDefault`, "get", params);
}

const getColumnSetInfo = (params) => {
    return CallAPI(`${newUrl}search/getColumnSetInfo`, "get", params);
}

const saveTemplateField = (params) => {
    return CallAPI(`${newUrl}search/saveTemplateField`, "POST", params);
}

const getSearchColumnInfo = (params) => {
    return CallAPI(`${newUrl}search/getSearchColumnInfo`, "get", params);
}

const batchEditSave = (params) => {
    return CallAPI(`${newUrl}search/batchEditSave`, "POST", params);
}
const checkDataChange = (params) => {
    return CallAPI(`${newUrl}search/checkDataChange`, "POST", params);
}

const getBatchModifyField = (params) => {
    return CallAPI(`${newUrl}search/getBatchModifyField`, "GET", params);
}

const saveBatchModifyField = (params) => {
    return CallAPI(`${newUrl}search/saveBatchModifyField`, "POST", params);
}

const batchEditGetVerifyField = (params) => {
    return CallAPI(`${newUrl}search/batchEditGetVerifyField`, "GET", params);
}

const batchEditVerifyData = (params) => {
    return CallAPI(`${newUrl}search/batchEditVerifyData`, "POST", params);
}

const getAppInfoByID = (params) => {
    return CallAPI(`${newUrl}mode/app/getAppInfoByID`, "GET", params);
}

const getJsCodeArea = (params) => {
    return CallAPI(`${newUrl}list/getJsCodeArea`, "GET", params);
}

const checkDataIsChange = (params) => {
    return CallAPI(`${newUrl}search/checkDataIsChange`, "GET", params);
}
const doExcelExpost = (params) => {
    return CallAPI(`${newUrl}search/doExcelExpost`, "POST", params);
}
const getExcelExpProgress = (params) => {
    return CallAPI(`${newUrl}search/getExcelExpProgress`, "GET", params);
}
const cancelExcelExp = (params) => {
    return CallAPI(`${newUrl}search/cancelExcelExp`, "POST", params);
}
const checkCanExcelExp = (params) => {
    return CallAPI(`${newUrl}search/checkCanExcelExp`, "POST", params);
}
const getOriginalTableWidth = (params) => {
    return CallAPI(`${newUrl}search/getOriginalTableWidth`, "GET", params);
}
const backUpData = (params) => {
    return CallAPI(`/api/cube/mode/mode/backUpData`, "POST", params);
}
export const saveCubeLikeInfo = (params) => {
    return CallAPI(`${newUrl}new/card/saveCubeLikeInfo`, "get", params);
}
const doDelLoadingpost = (params) => {
    return CallAPI(`${newUrl}search/doDelLoadingpost`, "POST", params);
}
const getDelLoadingProgress = (params) => {
    return CallAPI(`${newUrl}search/getDelLoadingProgress`, "GET", params);
}

const modeSecondaryVerify = (params) => {
    return CallAPI(`${newUrl}search/modeSecondaryVerify`, "POST", params);
}

const updateFreeSecretTime = (params) => {
    return CallAPI(`${newUrl}search/updateFreeSecretTime`, "GET", params);
}

const showLittleCard = (params) => {
    return CallAPI(`${newUrl}list/showLittleCard`, "GET", params);
}
const saveLittleCardFieldValue = (params) => {
    return CallAPI(`${newUrl}list/saveLittleCardFieldValue`, "POST", params);
}
const getRowClickHref = (params) => {
    return CallAPI(`${newUrl}list/getRowClickHref`, "get", params);
}

export default {
    init,
    dataKey,
    cleanCol,
    datas,
    edit,
    update,
    doInterface,
    initSearch,
    deleteData,
    doDelLoadingpost,
    getDelLoadingProgress,
    getConditionInfo,
    getAdvancedInfo,
    getTitleField,
    getBarCode,
    getQrCode,
    getConditionParams,
    getTemplates,
    getTemplateInfo,
    saveTemplate,
    batchShareCondition,
    saveBatchShare,
    analyzePageExpandLinkUrl,
    getMapTitles,
    batchSave,
    saveTabBatch,
    getTemplateList,
    saveOrUpdateTemplate,
    deleteTemplate,
    setDefault,
    getColumnSetInfo,
    saveTemplateField,
    getSearchColumnInfo,
    batchEditSave,
    checkDataChange,
    getBatchModifyField,
    saveBatchModifyField,
    batchEditGetVerifyField,
    batchEditVerifyData,
    getAppInfoByID,
    getJsCodeArea,
    checkDataIsChange,
    doExcelExpost,
    getExcelExpProgress,
    cancelExcelExp,
    checkCanExcelExp,
    getOriginalTableWidth,
    backUpData,
    saveCubeLikeInfo,
    modeSecondaryVerify,
    updateFreeSecretTime,
    showLittleCard,
    saveLittleCardFieldValue,
    getRowClickHref,
    getCountData,
    getGroupData
}